using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;
using DG.Tweening;

public class DOTweenAnimationBinder : BinderBase
{
    public enum AttributeType : int
    {
        targetIsSelf,
        tweenTargetIsTargetGO,
        delay,
        duration,
        loops,
        id,
        isRelative,
        isFrom,
        isIndependentUpdate,
        autoKill,
        isActive,
        isValid,
        autoPlay,
        useTargetAsV3,
        endValueFloat,
        endValueV3,
        endValueV2,
        endValueColor,
        endValueString,
        endValueRect,
        optionalBool0,
        optionalFloat0,
        optionalInt0,
        optionalString,
        isSpeedBased,
        hasOnStart,
        hasOnPlay,
        hasOnUpdate,
        hasOnStepComplete,
        hasOnComplete,
        hasOnTweenCreated,
        hasOnRewind,
        onStart,
        onPlay,
        onUpdate,
        onStepComplete,
        onComplete,
        onTweenCreated,
        onRewind,
        enabled,
    }
    
    private DOTweenAnimation _target;
    
    public DOTweenAnimationBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public DOTweenAnimationBinder()
    {
        
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<DOTweenAnimation>();
        _active = _target != null;
    }

    public override void Dispose()
    {
        _target = null;
        base.Dispose();
    }

    public override void SetBoolean(bool value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.targetIsSelf:
                _target.targetIsSelf = value;
            break;
            case AttributeType.tweenTargetIsTargetGO:
                _target.tweenTargetIsTargetGO = value;
            break;
            case AttributeType.isRelative:
                _target.isRelative = value;
            break;
            case AttributeType.isFrom:
                _target.isFrom = value;
            break;
            case AttributeType.isIndependentUpdate:
                _target.isIndependentUpdate = value;
            break;
            case AttributeType.autoKill:
                _target.autoKill = value;
            break;
            case AttributeType.isActive:
                _target.isActive = value;
            break;
            case AttributeType.isValid:
                _target.isValid = value;
            break;
            case AttributeType.autoPlay:
                _target.autoPlay = value;
            break;
            case AttributeType.useTargetAsV3:
                _target.useTargetAsV3 = value;
            break;
            case AttributeType.optionalBool0:
                _target.optionalBool0 = value;
            break;
            case AttributeType.isSpeedBased:
                _target.isSpeedBased = value;
            break;
            case AttributeType.hasOnStart:
                _target.hasOnStart = value;
            break;
            case AttributeType.hasOnPlay:
                _target.hasOnPlay = value;
            break;
            case AttributeType.hasOnUpdate:
                _target.hasOnUpdate = value;
            break;
            case AttributeType.hasOnStepComplete:
                _target.hasOnStepComplete = value;
            break;
            case AttributeType.hasOnComplete:
                _target.hasOnComplete = value;
            break;
            case AttributeType.hasOnTweenCreated:
                _target.hasOnTweenCreated = value;
            break;
            case AttributeType.hasOnRewind:
                _target.hasOnRewind = value;
            break;
            case AttributeType.enabled:
                _target.enabled = value;
            break;
            default:
            break;
        }
        base.SetBoolean(value);
    }
    
    public override void SetSingle(float value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.delay:
                _target.delay = value;
            break;
            case AttributeType.duration:
                _target.duration = value;
            break;
            case AttributeType.endValueFloat:
                _target.endValueFloat = value;
            break;
            case AttributeType.optionalFloat0:
                _target.optionalFloat0 = value;
            break;
            default:
            break;
        }
        base.SetSingle(value);
    }
    
    public override void SetInt32(int value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.loops:
                _target.loops = value;
            break;
            case AttributeType.optionalInt0:
                _target.optionalInt0 = value;
            break;
            default:
            break;
        }
        base.SetInt32(value);
    }
    
    public override void SetString(string value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.id:
                _target.id = value;
            break;
            case AttributeType.endValueString:
                _target.endValueString = value;
            break;
            case AttributeType.optionalString:
                _target.optionalString = value;
            break;
            default:
            break;
        }
        base.SetString(value);
    }
    
    public override void SetVector3(Vector3 value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.endValueV3:
                _target.endValueV3 = value;
            break;
            default:
            break;
        }
        base.SetVector3(value);
    }
    
    public override void SetVector2(Vector2 value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.endValueV2:
                _target.endValueV2 = value;
            break;
            default:
            break;
        }
        base.SetVector2(value);
    }
    
    public override void SetColor(Color value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.endValueColor:
                _target.endValueColor = value;
            break;
            default:
            break;
        }
        base.SetColor(value);
    }
    
    public override void SetRect(Rect value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.endValueRect:
                _target.endValueRect = value;
            break;
            default:
            break;
        }
        base.SetRect(value);
    }
    
    public override void SetAction(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onStart:
                _target.onStart.AddListener(action);
            break;
            case AttributeType.onPlay:
                _target.onPlay.AddListener(action);
            break;
            case AttributeType.onUpdate:
                _target.onUpdate.AddListener(action);
            break;
            case AttributeType.onStepComplete:
                _target.onStepComplete.AddListener(action);
            break;
            case AttributeType.onComplete:
                _target.onComplete.AddListener(action);
            break;
            case AttributeType.onTweenCreated:
                _target.onTweenCreated.AddListener(action);
            break;
            case AttributeType.onRewind:
                _target.onRewind.AddListener(action);
            break;
            default:
            break;
        }
        base.SetAction(action);
    }
    
    public override void RemoveAction(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onStart:
                _target.onStart.RemoveListener(action);
            break;
            case AttributeType.onPlay:
                _target.onPlay.RemoveListener(action);
            break;
            case AttributeType.onUpdate:
                _target.onUpdate.RemoveListener(action);
            break;
            case AttributeType.onStepComplete:
                _target.onStepComplete.RemoveListener(action);
            break;
            case AttributeType.onComplete:
                _target.onComplete.RemoveListener(action);
            break;
            case AttributeType.onTweenCreated:
                _target.onTweenCreated.RemoveListener(action);
            break;
            case AttributeType.onRewind:
                _target.onRewind.RemoveListener(action);
            break;
            default:
            break;
        }
        base.RemoveAction(action);
    }
    
    public override void RemoveAllAction()
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onStart:
                _target.onStart.RemoveAllListeners();
            break;
            case AttributeType.onPlay:
                _target.onPlay.RemoveAllListeners();
            break;
            case AttributeType.onUpdate:
                _target.onUpdate.RemoveAllListeners();
            break;
            case AttributeType.onStepComplete:
                _target.onStepComplete.RemoveAllListeners();
            break;
            case AttributeType.onComplete:
                _target.onComplete.RemoveAllListeners();
            break;
            case AttributeType.onTweenCreated:
                _target.onTweenCreated.RemoveAllListeners();
            break;
            case AttributeType.onRewind:
                _target.onRewind.RemoveAllListeners();
            break;
            default:
            break;
        }
    }
    
}